package com.wxdc.nmgyt.nmgytwydc.presenter;

import com.wxdc.nmgyt.nmgytwydc.base.RxPersenter;
import com.wxdc.nmgyt.nmgytwydc.http.RetrofitHelper;
import com.wxdc.nmgyt.nmgytwydc.model.CommitDataBean;
import com.wxdc.nmgyt.nmgytwydc.model.SCommitDataBean;
import com.wxdc.nmgyt.nmgytwydc.presenter.contract.ToCommitDataContract;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;

/**
 * Created by Administrator on 2018/7/24.
 */

public class ToCommitDataPersenter extends RxPersenter<ToCommitDataContract.View> implements ToCommitDataContract.Persenter{

    private RetrofitHelper mRetrofitHelper;
    @Inject
    public ToCommitDataPersenter(RetrofitHelper retrofitHelper) {
        mRetrofitHelper = retrofitHelper;
    }

    @Override
    public void DataUpload(List<SCommitDataBean> dataBeans, String curtUserId, String upUserid) {
        mRetrofitHelper.upLoadData(dataBeans, curtUserId, upUserid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResponseBody>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        addDisposable(d);
                    }

                    @Override
                    public void onNext(ResponseBody responseBody) {
                        mView.DataUploadOkBackResult(responseBody);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.showError("error");
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
